cmake_minimum_required(VERSION 3.1)
project(pyQPandaOperator)

set(LIB_PYQPANDA_OPERATOR pyQPandaOperator)
file(GLOB_RECURSE PYQPANDA_OPERATOR_SRC *.cpp)
pybind11_add_module(${LIB_PYQPANDA_OPERATOR} SHARED ${PYQPANDA_OPERATOR_SRC})
set_target_properties(${LIB_PYQPANDA_OPERATOR}  PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
target_link_libraries(${LIB_PYQPANDA_OPERATOR} PRIVATE ${LIB_QPANDA} ${LIB_QALG} ${LIB_VAR})


set(PYOPERATOR_OUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../pyQPanda/pyqpanda/Operator")
set(PYOPERATOR_OUT_LIB
        "${PYTHON_MODULE_PREFIX}${LIB_PYQPANDA_OPERATOR}${PYTHON_MODULE_EXTENSION}")

add_custom_command(OUTPUT COPY_RES
   COMMAND ${CMAKE_COMMAND} -E copy ${EXECUTABLE_OUTPUT_PATH}/${PYOPERATOR_OUT_LIB} ${PYOPERATOR_OUT_PATH}
 )
add_custom_target(CopyQPandaTaskOperator ALL DEPENDS COPY_RES ${LIB_PYQPANDA_OPERATOR})

# generate stub file for IDE intelliSense 
if(PYQPANDA_STUBGEN)
    add_custom_command(TARGET CopyQPandaTaskOperator
        POST_BUILD
        COMMAND ${PYTHON_EXECUTABLE} ${PYQPANDA_STUBGEN} -m ${LIB_PYQPANDA_OPERATOR} -o ${PYOPERATOR_OUT_PATH}
        WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
        VERBATIM
        USES_TERMINAL
        )
endif(PYQPANDA_STUBGEN)
